/**    
 * @{#} WXEntryActivity.java Create on 2014年7月28日 下午3:57:13    
 *    
 * @author <a href="mailto:evan0502@qq.com">Evan</a>   
 * @version 1.0    
 */
package com.smiier.skin.wxapi;

import android.os.Bundle;

import com.evan.common.share.ShareWXUtils;
import com.smiier.skin.LoginActivity;
import com.smiier.skin.net.SysShareCallBackTask;
import com.smiier.skin.net.SysShareCallBackTask.SysShareCallBackRequest;
import com.smiier.skin.ui.BasicActivity;
import com.smiier.skin.util.GlobalSettings;
import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.modelmsg.SendAuth;
import com.tencent.mm.sdk.modelmsg.SendAuth.Resp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;
import com.umeng.analytics.MobclickAgent;

public class WXEntryActivity extends BasicActivity implements
		IWXAPIEventHandler {

	private IWXAPI api;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		api = WXAPIFactory.createWXAPI(this, ShareWXUtils.APP_ID, false);
		api.handleIntent(getIntent(), this);
	}

	@Override
	public void onReq(BaseReq req) {

	}

	@Override
	public void onResp(BaseResp resp) {
		switch (resp.errCode) {
		case BaseResp.ErrCode.ERR_OK:
			try {
				SendAuth.Resp res = (Resp) resp;
				LoginActivity.code = res.code;
			} catch (Exception e) {
			}
			if (resp.transaction != null) {
				if (resp.transaction.contains("webpage")) {// 分享回调
					SysShareCallBackRequest req = new SysShareCallBackRequest();
					req.token = GlobalSettings.sToken;
					SysShareCallBackTask task = new SysShareCallBackTask();
					task.setRequest(req);
					task.setContext(this.getApplicationContext());
					task.start();
				}
			}

			break;
		}
		finish();
	}
	
	@Override
	public void onResume() {
		super.onResume();
		MobclickAgent.onResume(getContext());
	}

	@Override
	public void onPause() {
		super.onPause();
		MobclickAgent.onPause(getContext());
	}
	
	
	
}
